
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 06/23/2014 22:54:47
-- Generated from EDMX file: D:\Projects\PIB\PIB\PIBDataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [PIB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_PrestatieIndicatorPIBeoordeling]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PIBeoordelingSet] DROP CONSTRAINT [FK_PrestatieIndicatorPIBeoordeling];
GO
IF OBJECT_ID(N'[dbo].[FK_PIBeoordelingSmartzinnen_PIBeoordeling]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PIBeoordelingSmartzinnen] DROP CONSTRAINT [FK_PIBeoordelingSmartzinnen_PIBeoordeling];
GO
IF OBJECT_ID(N'[dbo].[FK_PIBeoordelingSmartzinnen_Smartzinnen]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PIBeoordelingSmartzinnen] DROP CONSTRAINT [FK_PIBeoordelingSmartzinnen_Smartzinnen];
GO
IF OBJECT_ID(N'[dbo].[FK_PIBeoordelingBeoordeling]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PIBeoordelingSet] DROP CONSTRAINT [FK_PIBeoordelingBeoordeling];
GO
IF OBJECT_ID(N'[dbo].[FK_BeoordelingStudent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BeoordelingSet] DROP CONSTRAINT [FK_BeoordelingStudent];
GO
IF OBJECT_ID(N'[dbo].[FK_SchoolVak]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VakSet] DROP CONSTRAINT [FK_SchoolVak];
GO
IF OBJECT_ID(N'[dbo].[FK_VakBeoordeling]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BeoordelingSet] DROP CONSTRAINT [FK_VakBeoordeling];
GO
IF OBJECT_ID(N'[dbo].[FK_DocentVak]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VakSet] DROP CONSTRAINT [FK_DocentVak];
GO
IF OBJECT_ID(N'[dbo].[FK_DocentVak1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VakSet] DROP CONSTRAINT [FK_DocentVak1];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[PIBeoordelingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PIBeoordelingSet];
GO
IF OBJECT_ID(N'[dbo].[VakSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VakSet];
GO
IF OBJECT_ID(N'[dbo].[BeoordelingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BeoordelingSet];
GO
IF OBJECT_ID(N'[dbo].[DocentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DocentSet];
GO
IF OBJECT_ID(N'[dbo].[SchoolSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SchoolSet];
GO
IF OBJECT_ID(N'[dbo].[SmartzinnenSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SmartzinnenSet];
GO
IF OBJECT_ID(N'[dbo].[StudentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StudentSet];
GO
IF OBJECT_ID(N'[dbo].[PrestatieIndicatorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PrestatieIndicatorSet];
GO
IF OBJECT_ID(N'[dbo].[PIBeoordelingSmartzinnen]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PIBeoordelingSmartzinnen];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'PIBeoordelingSet'
CREATE TABLE [dbo].[PIBeoordelingSet] (
    [PIBeoordelingId] int IDENTITY(1,1) NOT NULL,
    [PICijfer] int  NOT NULL,
    [Opmerking] nvarchar(max)  NOT NULL,
    [PrestatieIndicator_PIId] int  NOT NULL,
    [Beoordeling_BeoordelingId] int  NOT NULL
);
GO

-- Creating table 'VakSet'
CREATE TABLE [dbo].[VakSet] (
    [VakId] int IDENTITY(1,1) NOT NULL,
    [VakNaam] nvarchar(max)  NOT NULL,
    [Totaal] nvarchar(max)  NOT NULL,
    [Gesloten] nvarchar(max)  NOT NULL,
    [School_SchoolId] int  NOT NULL,
    [Beoordelaar_DocentId] int  NOT NULL,
    [Examinator_DocentId] int  NOT NULL
);
GO

-- Creating table 'BeoordelingSet'
CREATE TABLE [dbo].[BeoordelingSet] (
    [BeoordelingId] int IDENTITY(1,1) NOT NULL,
    [Eindcijfer] int  NOT NULL,
    [Geslotendatum] nvarchar(max)  NOT NULL,
    [Student_StudentId] int  NOT NULL,
    [Vak_VakId] int  NOT NULL
);
GO

-- Creating table 'DocentSet'
CREATE TABLE [dbo].[DocentSet] (
    [DocentId] int IDENTITY(1,1) NOT NULL,
    [DocentNaam] nvarchar(max)  NOT NULL,
    [Beheerder] bit  NOT NULL,
    [Gebruikersnaam] nvarchar(max)  NOT NULL,
    [Wachtwoord] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SchoolSet'
CREATE TABLE [dbo].[SchoolSet] (
    [SchoolId] int IDENTITY(1,1) NOT NULL,
    [SchoolNaam] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SmartzinnenSet'
CREATE TABLE [dbo].[SmartzinnenSet] (
    [SmartId] int IDENTITY(1,1) NOT NULL,
    [SmartZin] nvarchar(max)  NOT NULL,
    [SmartCijfer] int  NOT NULL
);
GO

-- Creating table 'StudentSet'
CREATE TABLE [dbo].[StudentSet] (
    [StudentId] int IDENTITY(1,1) NOT NULL,
    [StudentNaam] nvarchar(max)  NOT NULL,
    [Gebruikersnaam] nvarchar(max)  NOT NULL,
    [Wachtwoord] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'PrestatieIndicatorSet'
CREATE TABLE [dbo].[PrestatieIndicatorSet] (
    [PIId] int IDENTITY(1,1) NOT NULL,
    [PINaam] nvarchar(max)  NOT NULL,
    [PIOmschrijving] nvarchar(max)  NOT NULL,
    [PIGewicht] int  NOT NULL
);
GO

-- Creating table 'PIBeoordelingSmartzinnen'
CREATE TABLE [dbo].[PIBeoordelingSmartzinnen] (
    [PIBeoordeling_PIBeoordelingId] int  NOT NULL,
    [Smartzinnen_SmartId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [PIBeoordelingId] in table 'PIBeoordelingSet'
ALTER TABLE [dbo].[PIBeoordelingSet]
ADD CONSTRAINT [PK_PIBeoordelingSet]
    PRIMARY KEY CLUSTERED ([PIBeoordelingId] ASC);
GO

-- Creating primary key on [VakId] in table 'VakSet'
ALTER TABLE [dbo].[VakSet]
ADD CONSTRAINT [PK_VakSet]
    PRIMARY KEY CLUSTERED ([VakId] ASC);
GO

-- Creating primary key on [BeoordelingId] in table 'BeoordelingSet'
ALTER TABLE [dbo].[BeoordelingSet]
ADD CONSTRAINT [PK_BeoordelingSet]
    PRIMARY KEY CLUSTERED ([BeoordelingId] ASC);
GO

-- Creating primary key on [DocentId] in table 'DocentSet'
ALTER TABLE [dbo].[DocentSet]
ADD CONSTRAINT [PK_DocentSet]
    PRIMARY KEY CLUSTERED ([DocentId] ASC);
GO

-- Creating primary key on [SchoolId] in table 'SchoolSet'
ALTER TABLE [dbo].[SchoolSet]
ADD CONSTRAINT [PK_SchoolSet]
    PRIMARY KEY CLUSTERED ([SchoolId] ASC);
GO

-- Creating primary key on [SmartId] in table 'SmartzinnenSet'
ALTER TABLE [dbo].[SmartzinnenSet]
ADD CONSTRAINT [PK_SmartzinnenSet]
    PRIMARY KEY CLUSTERED ([SmartId] ASC);
GO

-- Creating primary key on [StudentId] in table 'StudentSet'
ALTER TABLE [dbo].[StudentSet]
ADD CONSTRAINT [PK_StudentSet]
    PRIMARY KEY CLUSTERED ([StudentId] ASC);
GO

-- Creating primary key on [PIId] in table 'PrestatieIndicatorSet'
ALTER TABLE [dbo].[PrestatieIndicatorSet]
ADD CONSTRAINT [PK_PrestatieIndicatorSet]
    PRIMARY KEY CLUSTERED ([PIId] ASC);
GO

-- Creating primary key on [PIBeoordeling_PIBeoordelingId], [Smartzinnen_SmartId] in table 'PIBeoordelingSmartzinnen'
ALTER TABLE [dbo].[PIBeoordelingSmartzinnen]
ADD CONSTRAINT [PK_PIBeoordelingSmartzinnen]
    PRIMARY KEY CLUSTERED ([PIBeoordeling_PIBeoordelingId], [Smartzinnen_SmartId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [PrestatieIndicator_PIId] in table 'PIBeoordelingSet'
ALTER TABLE [dbo].[PIBeoordelingSet]
ADD CONSTRAINT [FK_PrestatieIndicatorPIBeoordeling]
    FOREIGN KEY ([PrestatieIndicator_PIId])
    REFERENCES [dbo].[PrestatieIndicatorSet]
        ([PIId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PrestatieIndicatorPIBeoordeling'
CREATE INDEX [IX_FK_PrestatieIndicatorPIBeoordeling]
ON [dbo].[PIBeoordelingSet]
    ([PrestatieIndicator_PIId]);
GO

-- Creating foreign key on [PIBeoordeling_PIBeoordelingId] in table 'PIBeoordelingSmartzinnen'
ALTER TABLE [dbo].[PIBeoordelingSmartzinnen]
ADD CONSTRAINT [FK_PIBeoordelingSmartzinnen_PIBeoordeling]
    FOREIGN KEY ([PIBeoordeling_PIBeoordelingId])
    REFERENCES [dbo].[PIBeoordelingSet]
        ([PIBeoordelingId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Smartzinnen_SmartId] in table 'PIBeoordelingSmartzinnen'
ALTER TABLE [dbo].[PIBeoordelingSmartzinnen]
ADD CONSTRAINT [FK_PIBeoordelingSmartzinnen_Smartzinnen]
    FOREIGN KEY ([Smartzinnen_SmartId])
    REFERENCES [dbo].[SmartzinnenSet]
        ([SmartId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PIBeoordelingSmartzinnen_Smartzinnen'
CREATE INDEX [IX_FK_PIBeoordelingSmartzinnen_Smartzinnen]
ON [dbo].[PIBeoordelingSmartzinnen]
    ([Smartzinnen_SmartId]);
GO

-- Creating foreign key on [Beoordeling_BeoordelingId] in table 'PIBeoordelingSet'
ALTER TABLE [dbo].[PIBeoordelingSet]
ADD CONSTRAINT [FK_PIBeoordelingBeoordeling]
    FOREIGN KEY ([Beoordeling_BeoordelingId])
    REFERENCES [dbo].[BeoordelingSet]
        ([BeoordelingId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PIBeoordelingBeoordeling'
CREATE INDEX [IX_FK_PIBeoordelingBeoordeling]
ON [dbo].[PIBeoordelingSet]
    ([Beoordeling_BeoordelingId]);
GO

-- Creating foreign key on [Student_StudentId] in table 'BeoordelingSet'
ALTER TABLE [dbo].[BeoordelingSet]
ADD CONSTRAINT [FK_BeoordelingStudent]
    FOREIGN KEY ([Student_StudentId])
    REFERENCES [dbo].[StudentSet]
        ([StudentId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BeoordelingStudent'
CREATE INDEX [IX_FK_BeoordelingStudent]
ON [dbo].[BeoordelingSet]
    ([Student_StudentId]);
GO

-- Creating foreign key on [School_SchoolId] in table 'VakSet'
ALTER TABLE [dbo].[VakSet]
ADD CONSTRAINT [FK_SchoolVak]
    FOREIGN KEY ([School_SchoolId])
    REFERENCES [dbo].[SchoolSet]
        ([SchoolId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SchoolVak'
CREATE INDEX [IX_FK_SchoolVak]
ON [dbo].[VakSet]
    ([School_SchoolId]);
GO

-- Creating foreign key on [Vak_VakId] in table 'BeoordelingSet'
ALTER TABLE [dbo].[BeoordelingSet]
ADD CONSTRAINT [FK_VakBeoordeling]
    FOREIGN KEY ([Vak_VakId])
    REFERENCES [dbo].[VakSet]
        ([VakId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VakBeoordeling'
CREATE INDEX [IX_FK_VakBeoordeling]
ON [dbo].[BeoordelingSet]
    ([Vak_VakId]);
GO

-- Creating foreign key on [Beoordelaar_DocentId] in table 'VakSet'
ALTER TABLE [dbo].[VakSet]
ADD CONSTRAINT [FK_DocentVak]
    FOREIGN KEY ([Beoordelaar_DocentId])
    REFERENCES [dbo].[DocentSet]
        ([DocentId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DocentVak'
CREATE INDEX [IX_FK_DocentVak]
ON [dbo].[VakSet]
    ([Beoordelaar_DocentId]);
GO

-- Creating foreign key on [Examinator_DocentId] in table 'VakSet'
ALTER TABLE [dbo].[VakSet]
ADD CONSTRAINT [FK_DocentVak1]
    FOREIGN KEY ([Examinator_DocentId])
    REFERENCES [dbo].[DocentSet]
        ([DocentId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DocentVak1'
CREATE INDEX [IX_FK_DocentVak1]
ON [dbo].[VakSet]
    ([Examinator_DocentId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------